/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.opgea.crm.domain.entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.opgea.crm.domain.entities.security.CrmUser;

/**
 *
 * @author Admin
 */
	@Entity
	@Table(name = "opportunity")
	@NamedQueries({
	@NamedQuery(name = "Opportunity.findAll", query = "SELECT o FROM Opportunity o")})
    public class Opportunity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue
    @Basic(optional = false)
    @Column(name = "id", nullable = false)
    private Long id;
    
    @Column(name = "opportunityTitle", length = 45)
    private String opportunityTitle;
    
    @Column(name = "dealSize")
    private Integer dealSize;
    
    @Lob
    @Column(name = "opportunityDescription")
    private byte[] opportunityDescription;
    @ManyToOne(cascade=CascadeType.REFRESH)
    @JoinColumn(name = "opportunityStatus")
    private SetupsValue opportunityStatus;
    
    @ManyToOne(cascade=CascadeType.REFRESH)
    @JoinColumn(name = "confidenceLevel")
    private SetupsValue confidenceLevel;
    @ManyToOne(cascade=CascadeType.REFRESH)
    @JoinColumn(name = "stage")
    private SetupsValue stage;
    
    @Column(name = "forecastClosingDate")
    @Temporal(TemporalType.DATE)
    private Date forecastClosingDate;
    
    @Column(name = "actualCloseDate")
    @Temporal(TemporalType.DATE)
    private Date actualCloseDate;
    

    @Column(name = "createdDate")
    @Temporal(TemporalType.DATE)
    private Date createdDate;
    
    @JoinColumn(name = "salesPerson_id", referencedColumnName = "id")
    @ManyToOne
    private Employee salesPerson;
    
    @JoinColumn(name = "contact_id", referencedColumnName = "id")
    @ManyToOne
    private Lead relatedContact;
    
    @OneToMany(mappedBy = "opportunity")
    private Collection<Activity> activityCollection;
    
	@ManyToOne(cascade=CascadeType.REFRESH)
	@JoinColumn(name="createdBy", referencedColumnName="username")
	private CrmUser createdBy;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="createdat")
	private Date createdAt;    

    public Opportunity() {
    }

    public Opportunity(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getOpportunityTitle() {
        return opportunityTitle;
    }

    public void setOpportunityTitle(String opportunityTitle) {
        this.opportunityTitle = opportunityTitle;
    }
    
   

    public SetupsValue getStage() {
        return stage;
    }

    public void setStage(SetupsValue stage) {
        this.stage = stage;
    }

    public Integer getDealSize() {
        return dealSize;
    }

    public void setDealSize(Integer dealSize) {
        this.dealSize = dealSize;
    }

    public byte[] getOpportunityDescription() {
        return opportunityDescription;
    }

    public void setOpportunityDescription(byte[] opportunityDescription) {
        this.opportunityDescription = opportunityDescription;
    }

    public SetupsValue getOpportunityStatus() {
        return opportunityStatus;
    }

    public void setOpportunityStatus(SetupsValue opportunityStatus) {
        this.opportunityStatus = opportunityStatus;
    }

    public SetupsValue getConfidenceLevel() {
        return confidenceLevel;
    }

    public void setConfidenceLevel(SetupsValue confidenceLevel) {
        this.confidenceLevel = confidenceLevel;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public Date getForecastClosingDate() {
        return forecastClosingDate;
    }

    public void setForecastClosingDate(Date forecastClosingDate) {
        this.forecastClosingDate = forecastClosingDate;
    }

    public Date getActualCloseDate() {
        return actualCloseDate;
    }

    public void setActualCloseDate(Date actualCloseDate) {
        this.actualCloseDate = actualCloseDate;
    }

    public Employee getSalesPerson() {
            return salesPerson;
    }

    public void setSalesPerson(Employee salesPerson) {
            this.salesPerson = salesPerson;
    }

    public Lead getRelatedContact() {
            return relatedContact;
    }

    public void setRelatedContact(Lead relatedContact) {
            this.relatedContact = relatedContact;
    }

    public Collection<Activity> getActivityCollection() {
        return activityCollection;
    }

    public void setActivityCollection(Collection<Activity> activityCollection) {
        this.activityCollection = activityCollection;
    }

	public void setCreatedBy(CrmUser createdBy) {
		this.createdBy = createdBy;
	}

	public CrmUser getCreatedBy() {
		return createdBy;
	}

	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}

	public Date getCreatedAt() {
		return createdAt;
	}

	@Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Opportunity)) {
            return false;
        }
        Opportunity other = (Opportunity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.crm.domain.Opportunity[id=" + id + "]";
    }
}
